/*
 * Copyright (c) 2020. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.evenmo.string;

/**
 * This is Description 模拟死锁现象
 *
 * @author moyongjun
 * @date 2020/01/02
 */
public class ThreadDemo_sisuo implements Runnable{

    Object a=new Object();
    Object b=new Object();
    @Override
    public void run(){

        ma();
    }

    public void ma(){
        synchronized (a){
            System.out.println("持有了a的锁，想要b🔐");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            mb();
        }
    }

    public void mb(){
        synchronized (b){
            System.out.println("持有了b的锁，想要a🔐");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //ma();//反向加锁造成死锁
        }
    }


    public static void main(String[] args) {

        Thread t=new Thread(new ThreadDemo_sisuo(),"线程1");

        t.start();

    }
}
